package cc.autoapi.pucong.auto.flow.provider.group.controller;

import cc.autoapi.pucong.auto.flow.core.root.entity.BatchDeleteIdDto;
import cc.autoapi.pucong.auto.flow.core.root.exception.AutoFlowBaseController;
import cc.autoapi.pucong.auto.flow.core.root.exception.AutoFlowExceptionHandler;
import cc.autoapi.pucong.auto.flow.core.root.utils.Res;
import cc.autoapi.pucong.auto.flow.provider.group.entity.GroupInfoInsertDto;
import cc.autoapi.pucong.auto.flow.provider.group.entity.GroupInfoSelectDto;
import cc.autoapi.pucong.auto.flow.provider.group.entity.GroupInfoUpdateDto;
import cc.autoapi.pucong.auto.flow.provider.group.entity.GroupInfoVo;
import cc.autoapi.pucong.auto.flow.provider.group.service.GroupInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author pucong
 * @url https://gitee.com/pucong
 * @create 2023-05-31
 */
@RestController
@RequestMapping("/business/group/groupInfo")
public class GroupInfoController extends AutoFlowBaseController implements AutoFlowExceptionHandler{

    @Autowired
    private GroupInfoService groupInfoService;

    @GetMapping("/getGroupInfoList")
    public Res<List<GroupInfoVo>> getGroupInfoList(GroupInfoSelectDto groupInfoSelectDto) {
        List<GroupInfoVo> groupInfoList = groupInfoService.getGroupInfoList(groupInfoSelectDto);
        return Res.ok(groupInfoList);
    }

    @GetMapping("/getGroupCount")
    public Res<Long> getGroupCount(GroupInfoSelectDto dto) {
        Long count = groupInfoService.getGroupCount(dto);
        return Res.ok(count);
    }

    @PostMapping("/insertGroupInfo")
    public Res<Integer> insertGroupInfo(@Validated @RequestBody GroupInfoInsertDto dto) {
        int i = groupInfoService.insertGroupInfo(dto);
        return Res.ok(i);
    }

    @PutMapping("/updateGroupInfoById/{id}")
    public Res<Integer> updateGroupInfoById(@PathVariable("id") String id,
                                            @Validated @RequestBody GroupInfoUpdateDto dto) {
        int i = groupInfoService.updateGroupInfoById(id, dto);
        return Res.ok(i);
    }

    @DeleteMapping("/batchDeleteGroupInfoByIds")
    public Res<Integer> batchDeleteGroupInfoByIds(BatchDeleteIdDto dto) {
        int i = groupInfoService.batchDeleteGroupInfoByIds(dto.getIdList());
        return Res.ok(i);
    }
}